package com.javaee.web.servlet;
import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.javaee.ejb.entity.Activity;
import com.javaee.ejb.session.remote.ActivityManagerRemote;
import com.javaee.web.HttpServletBase;
import com.javaee.web.SiteParameters;

/**
 * Servlet implementation class InvalidActivityServlet
 */
public class InvalidActivityServlet extends HttpServletBase {
	private static final long serialVersionUID = 1L;

	@EJB
	private ActivityManagerRemote activityManager;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public InvalidActivityServlet() {
		super();
	}

	@Override
	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int activityId = Integer.parseInt(request.getParameter("activityId"));

		Activity activity = activityManager.getById(activityId);

		activity.setIsValid(false);

		// Sauvegarde de l'activite
		activityManager.saveActivity(activity);

		// Redirection vers la page de gestion du projet
		response.sendRedirect(SiteParameters.getFullServletPath("project")
				+ "?projectId=" + activity.getProject().getId());
	}
}